﻿using System;

namespace PrototypePattern;

//原型模式
public class Message : ICloneable
{
    public string? Sender { get; init; }
    public string? Receiver { get; set; }
    public string? Content { get; init; }

    public object Clone() => MemberwiseClone(); //这里使用浅拷贝，有引用的成员可以再另行实例化
}

public static class Program
{
    private static void SendMessage(Message message)
    {
        Console.WriteLine($"发送方:{message.Sender},接收方:{message.Receiver},内容:{message.Content}");
    }

    public static void Main()
    {
        var originMessage = new Message
        {
            Sender = "中国移动",
            Content = "您本月消费为……"
        };

        for (var i = 0; i < 10; i++)
        {
            var cloneMessage = (Message)originMessage.Clone();
            cloneMessage.Receiver = $"测试用户{i}";
            SendMessage(cloneMessage);
        }
    }
}